# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=editorconfig-qtcreator
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.3.6
pkgrel=1
pkgdesc='EditorConfig Plugin for QtCreator (mingw-w64)'
url='https://github.com/editorconfig/editorconfig-qtcreator'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-pcre2"
         "${MINGW_PACKAGE_PREFIX}-qt-creator"
         "${MINGW_PACKAGE_PREFIX}-editorconfig-core-c"
         "${MINGW_PACKAGE_PREFIX}-syntax-highlighting-qt5")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-ninja")
options=('staticlibs')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/editorconfig/editorconfig-qtcreator/archive/${pkgver}.tar.gz"
        'editorconfig-qtcreator-0.3.6-set-cxx-standard.patch')
sha256sums=('b08acd26e601dbb408de8748b512f9e505865d55f2e8a4024930f44164d7882c'
            '707af33327e8351aec558e94e36ab539a1178a583fe4372379296e49cc8ae250')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}

  patch -p1 -i "${srcdir}"/editorconfig-qtcreator-0.3.6-set-cxx-standard.patch
}

build() {
  [[ -d ${srcdir}/build-${MSYSTEM} ]] && rm -rf ${srcdir}/build-${MSYSTEM}
  mkdir -p ${srcdir}/build-${MSYSTEM} && cd ${srcdir}/build-${MSYSTEM}

  if check_option "debug" "y"; then
    _build_type=Debug
  else
    _build_type=Release
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=${_build_type} \
    ../${_realname}-${pkgver}

  cmake --build .
}

package() {
  cd ${srcdir}/build-${MSYSTEM}

  DESTDIR="${pkgdir}" cmake --install .

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE.LGPLv21 ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.LGPLv21
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE.LGPLv3 ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.LGPLv3
}

